using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Phoenix.Framework
{
    public class HashSet<T> : ICollection<T>
    {
        readonly Dictionary<T, short> internalDictionary;

        public HashSet()
        {
            internalDictionary = new Dictionary<T, short>();
        }

        public void Add(T item)
        {
            if (!internalDictionary.ContainsKey(item))
                internalDictionary.Add(item, 0);
        }

        public void Clear()
        {
            internalDictionary.Clear();
        }

        public bool Contains(T item)
        {
            return internalDictionary.ContainsKey(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
        }

        public bool Remove(T item)
        {
            return internalDictionary.Remove(item);
        }

        public int Count
        {
            get { return internalDictionary.Keys.Count(); }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public IEnumerator<T> GetEnumerator()
        {
            return internalDictionary.Keys.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}